11/02/2015

Outline

  • What data does PVTA collect?
  • How can we access this data?
  • What do the data look like?

PVTA

PVTA bus

What about the bus tracker?

REST API

  • stands for Representational State Transfer (but that's not important)
  • Uses HTTP, the same protocol used to access web pages.
  • You have to know the syntax (inputs) and data structure (output)
    • We have a pdf for this.

PVTA API example:

Another one (more complicated)

R function to do the same thing:

# library(devtools)
# install_github("umassamherst-Grid/rpvta")
library(rpvta)
getRouteDetails
## function (routeID = "all") 
## {
##     baseUrl <- "http://bustracker.pvta.com/InfoPoint/rest/"
##     urlAppendage <- ifelse(routeID == "all", "routedetails/getallroutedetails", 
##         paste0("routedetails/get/", routeID))
##     queryUrl <- paste0(baseUrl, urlAppendage)
##     lookUp <- URLencode(queryUrl)
##     dat <- rjson::fromJSON(readLines(lookUp, warn = FALSE))
##     dat
## }
## <environment: namespace:rpvta>

The output of this function

b43details <- getRouteDetails(30043)
str(b43details, 1)
## List of 20
##  $ ServerId          : num 3
##  $ RouteId           : num 30043
##  $ RouteRecordId     : num 1
##  $ ShortName         : chr "B43"
##  $ LongName          : chr "Northampton/Hadley/Amherst"
##  $ RouteAbbreviation : chr "B43"
##  $ IvrDescription    : chr "Northampton Hadley Amherst"
##  $ Color             : chr "00467E"
##  $ TextColor         : chr "FFFFFF"
##  $ IsVisible         : logi TRUE
##  $ Group             : NULL
##  $ SortOrder         : num 13
##  $ RouteTraceFilename: chr "RouteB43.kml"
##  $ RouteTraceHash64  : NULL
##  $ IsHeadway         : logi FALSE
##  $ IncludeInGoogle   : logi TRUE
##  $ Stops             :List of 49
##  $ RouteStops        :List of 57
##  $ Directions        :List of 2
##  $ Vehicles          :List of 5

What else is in rpvta?

ls("package:rpvta")
##  [1] "bindRtDeets"        "busIcon"            "getCurrentMessages"
##  [4] "getDepartures"      "getRoute"           "getRouteDetails"   
##  [7] "getRouteID"         "getStops"           "getVehicles"       
## [10] "getVisibleRoutes"   "leafletBusLocs"     "nullToNa"          
## [13] "stopsToDF"          "toTime"             "vehicsToDf"        
## [16] "visRtsToDF"

Caveats:

  • This is a quick-and-dirty package.
  • Documentation is lacking
  • Function names are not consistent
  • Function output is not consistent

You can help!